import { ELJson } from "@/plugin/antvX6/node/type";
import { BuildFormCreate } from "@/plugin/formCreate/type";
import { adminFetch, useHandleApiRes } from "@/plugin/vueuse/http";

export namespace LiteFlowApi {
    /** 登录接口参数 */
    export interface NodeVO {
        id: string;
        type: string;
        label: string;
        model: string;
        clazz?: string;
        description?: string;
        cmpDataFormCreate?: BuildFormCreate[];
    }

    /** 登录接口返回值 */
    export interface ModelVO {
        label: string;
        model: string;
        description?: string;
    }

    export interface StencilVO {
        nodes: NodeVO[];
        models: ModelVO[];
    }

    export interface LiteFlowNode {
        id: string;
        type: string;
        clazz?: string;
    }
}


export const getJsonToEl = (json: any) => {
    return useHandleApiRes<string>(
        adminFetch("/liteflow/buildJsonToEl").post(json).json()
    );
}

export const getElToJson = (el: string, nodes: undefined | LiteFlowApi.LiteFlowNode[]) => {
    return useHandleApiRes<ELJson>(
        adminFetch("/liteflow/buildElToJson").post({ "el": el, "nodes": nodes }).json()
    );
}